package DynamicProgramming;

import java.util.Scanner;

public class 零一背包 {
    public static void main(String[] args) {
        /*Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int c = in.nextInt();
        int[] w = new int[n];
        int[] v = new int[n];
        for (int i = 0; i < n; i++) {
            w[i] = in.nextInt();
        }
        for (int i = 0; i < n; i++) {
            v[i] = in.nextInt();
        }
        int[][] dp = new int[n][c + 1];
        for (int i = w[0]; i <= c; i++) {
            dp[0][i] = v[0];
        }
        for (int i = 1; i < n; i++) {
            for (int j = 1; j <= c; j++) {
                if (j >= w[i]) dp[i][j] = Math.max(dp[i - 1][j], dp[i - 1][j - w[i]] + v[i]);
                else dp[i][j] = dp[i - 1][j];
            }
        }
        System.out.println(dp[n - 1][c]);*/

        // 滚动数组
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int c = in.nextInt();
        int[] w = new int[n];
        int[] v = new int[n];
        for (int i = 0; i < n; i++) {
            w[i] = in.nextInt();
        }
        for (int i = 0; i < n; i++) {
            v[i] = in.nextInt();
        }
        int[] dp = new int[c + 1];
        for (int i = 0; i < n; i++) {
            for (int j = c; j >= w[i]; j--) {
                dp[j] = Math.max(dp[j], dp[j - w[i]] + v[i]);
            }
        }
        System.out.println(dp[c]);
    }
}
